package com.tz.water.controller.common;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tz.water.bean.Device;
import com.tz.water.bean.User;
import com.tz.water.config.AccessLimit;
import com.tz.water.mapper.DeviceMapper;
import com.tz.water.utils.MyPasswordEncoder;
import com.tz.water.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/device")
public class DeviceController   {


    @Autowired
    DeviceMapper deviceMapper;

    @AccessLimit(times = 5)
    @PostMapping("/last")
    @ResponseBody
    public HashMap<String,Object> last (@RequestBody Object o, HttpServletRequest request) {
        Device device = deviceMapper.selectById(1);
        return ResponseUtils.success(device);
    }

    @AccessLimit(times = 5)
    @PostMapping("/openwater")
    @ResponseBody
    public HashMap<String,Object> openwater (@RequestBody Object o, HttpServletRequest request) {


        Device device = new Device();
        device.setId(1);
        device.setIsoutingwater(true);
        deviceMapper.updateById(device);
        return ResponseUtils.success(device);
    }

    @AccessLimit(times = 5)
    @PostMapping("/closewater")
    @ResponseBody
    public HashMap<String,Object> closewater (@RequestBody Object o, HttpServletRequest request) {

        Device device = new Device();
        device.setId(1);
        device.setIsoutingwater(false);
        deviceMapper.updateById(device);
        return ResponseUtils.success(device);
    }

}
